<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<link rel="stylesheet" href="style.css" media="screen">
		<s:head theme="ajax" debug="false"/>
		<script type="text/javascript">
			dojo.event.topic.subscribe("/save", function(data, type, request) {
			    if(type == "load") {
					dojo.byId("id").value = "";
					dojo.byId("name").value = "";
					dojo.byId("country").value = "";
				}
			});

			dojo.event.topic.subscribe("/edit", function(data, type, request) {
			    if(type == "before") {
					var id = data.split("_")[1];

					var tr = dojo.byId("row_"+id);
					var tds = tr.getElementsByTagName("td");

					dojo.byId("id").value = id;
					dojo.byId("name").value = dojo.string.trim(dojo.dom.textContent(tds[0]));
					dojo.byId("country").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
				}
			});
		</script>
	</head>
	<body>
	
		<s:if test="errors.size()>0">
			<div>
			<s:label>Erreurs</s:label>
			<ul><s:fielderror/></ul>
			</div>
		</s:if>
		
		<div class="box">				
			<div class="lb">
			<div class="rb">
			<div class="bb"><div class="blc"><div class="brc">
			<div class="tb"><div class="tlc"><div class="trc">
				
			<div id="content">	
				<p>Nouvelle marque</p>
				<s:form action="save" validate="true">
				    <s:textfield id="id" name="brand.id" cssStyle="display:none"/>
					<s:textfield id="name" label="Marque" name="brand.name"/>
					<s:textfield id="country" label="Pays" name="brand.country"/>
					<s:submit theme="ajax" targets="brands" notifyTopics="/save"/>					
				</s:form>
						
			</div>
			</div></div></div></div>
			</div></div></div></div>
		</div>
		<s:url action="list" id="descrsUrl"/>
		<div class="box">				

			<div class="lb">
			<div class="rb">
			<div class="bb"><div class="blc"><div class="brc">
			<div class="tb"><div class="tlc"><div class="trc">
					
			<div id="content">	
				<div style="text-align: right;">
    			<s:a theme="ajax" notifyTopics="/refresh">Refresh</s:a>
    		</div>
    		<s:div id="brands" theme="ajax" href="%{descrsUrl}" loadingText="Loading..." listenTopics="/refresh"/>
						
			</div>
			</div></div></div></div>
			</div></div></div></div>
		</div>
		
	</body>
</html>
